package starter;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Create by chenhd on 2021/9/4.
 */
@Configuration
@EnableConfigurationProperties(SchoolProperties.class)
@ConditionalOnClass(SchoolProperties.class)
public class SchoolAutoConfiguration {

    @Autowired
    private SchoolProperties schoolProperties;

    @Bean(value = "mySchool")
    @ConditionalOnMissingBean
    public School getSchool() {
        School school = new School();
        school.setName(schoolProperties.getName());
        school.setKlasses(schoolProperties.getMyClass());
        return school;
    }
}
